package main

import (
	"github.com/golang/protobuf/proto"
	logging "github.com/sirupsen/logrus"
	"webdemo/src/zinxgame/protobuf/demo"
)

func main() {
	person := &demo.Person{
		Name:   "zw",
		Age:    12,
		Emails: []string{"121@163.com", "323@qq.com"},
		Phones: []*demo.PhoneNumber{
			&demo.PhoneNumber{
				Number: "122",
				Type:   demo.PhoneType_HOME,
			},
			&demo.PhoneNumber{
				Number: "1333",
				Type:   demo.PhoneType_MOBILE,
			},
		},
	}
	// 序列化
	data, err := proto.Marshal(person)
	if err != nil {
		logging.Error("proto.Marshal error is ", err)
		return
	}
	// 反序列化
	newdata := &demo.Person{}
	err = proto.Unmarshal(data, newdata)
	if err != nil {
		logging.Error("proto.Unmarshal error is ", err)
		return
	}
	logging.Info("元数据:", data)
	logging.Info("反序列化后:", newdata)
}
